package com.example.config;

import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.env.Environment;
import org.springframework.core.type.AnnotatedTypeMetadata;

public class MacCondition implements Condition {
    /**
     *
     * ConditionContext 判定条件能使用的上下文环境
     * AnnotatedTypeMetadata 当前标注了Condition注解的注解信息
     */
    @Override
    public boolean matches(ConditionContext conditionContext, AnnotatedTypeMetadata annotatedTypeMetadata) {
        //conditionContext.getBeanFactory(); //获取创建工厂
        //conditionContext.getClassLoader();//
        //BeanDefinitionRegistry registry = conditionContext.getRegistry(); //bean注册类，可以注册移除或查询有没有哪个bean

        Environment environment = conditionContext.getEnvironment();
        String osname = environment.getProperty("os.name");
        if (osname != null && osname.contains("osx")) {
            return true;
        }
        return false;
    }
}



